package java_0620_FIleWriter_;

import java.io.FileWriter;
import java.io.IOException;

public class FileWriter_ {
    public static void main(String[] args) {
        String filePath = "e:\\hello.txt";
        FileWriter fileWriter =null;
        try {
            fileWriter = new FileWriter(filePath);
            //写入单个字符
            fileWriter.write('h');

            //写入指定数组
            char[] chars = new char[]{'a','b','c'};
            fileWriter.write(chars);

            //写入数组的指定部分
            fileWriter.write("爱莉希雅".toCharArray(),0,2);

            //写入整个字符串
            fileWriter.write("爱莉希雅");

            //写入字符串的指定部分
            fileWriter.write("爱莉希雅",0,2);
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            try {
                fileWriter.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
